package com.valuegroup.smarttodo.ui.programme.goals.detail;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.android.flexbox.FlexboxLayout;
import com.valuegroup.smarttodo.R;
import com.valuegroup.smarttodo.data.ServiceFactory;
import com.valuegroup.smarttodo.data.model.AppStatus;
import com.valuegroup.smarttodo.data.model.Event;
import com.valuegroup.smarttodo.data.model.Goals;
import com.valuegroup.smarttodo.data.model.Remark;
import com.valuegroup.smarttodo.data.model.Task;
import com.valuegroup.smarttodo.data.vo.GoalsEventVo;
import com.valuegroup.smarttodo.data.vo.TagVo;
import com.valuegroup.smarttodo.ui.programme.goals.GoalsRemarkActivity;
import com.valuegroup.smarttodo.ui.programme.goals.GoalsTagActivity;
import com.valuegroup.smarttodo.ui.programme.goals.GoalsTraceSourceActivity;
import com.valuegroup.smarttodo.plugins.ClickableTextView;
import com.valuegroup.smarttodo.plugins.chip.Chip;
import com.valuegroup.smarttodo.plugins.pickdialog.DatePickDialog;
import com.valuegroup.smarttodo.plugins.pickdialog.DateUtils;
import com.valuegroup.smarttodo.plugins.pickdialog.OnCustomSureLisener;
import com.valuegroup.smarttodo.plugins.pickdialog.OnSureLisener;
import com.valuegroup.smarttodo.plugins.pickdialog.bean.DateType;
import com.valuegroup.smarttodo.plugins.recyclerview.ItemTouchHelperAdapter;
import com.valuegroup.smarttodo.plugins.recyclerview.ItemTouchHelperViewHolder;
import com.valuegroup.smarttodo.ui.todo.task.detail.TaskDetailActivity;
import com.valuegroup.smarttodo.ui.todo.task.qucikadd.ChangeViewCallback;
import com.valuegroup.smarttodo.ui.todo.task.qucikadd.ExpansionCallback;
import com.valuegroup.smarttodo.ui.todo.task.qucikadd.QucikAddActivity;
import com.valuegroup.smarttodo.ui.todo.task.qucikadd.QucikAddEditText;
import com.valuegroup.smarttodo.ui.todo.task.qucikadd.QucikAddInputCheckRule;
import com.valuegroup.smarttodo.ui.todo.task.qucikadd.QuickAddEditorCallback;
import com.valuegroup.smarttodo.ui.todo.task.qucikadd.QuickAddHolder;
import com.valuegroup.smarttodo.util.AlertUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import androidx.appcompat.widget.PopupMenu;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 任务详情步骤列表
 */
public class GoalsDetailAdapter extends RecyclerView.Adapter implements ItemTouchHelperAdapter {

    private static final String TAG = GoalsDetailAdapter.class.getSimpleName();

    private final Context mContext;
    private RecyclerView recyclerView;
    private Long goalId;
    private List<GoalsEventVo> mDatas = new ArrayList<>();


    public GoalsDetailAdapter(Context context, RecyclerView recyclerView, Long id) {
        this.mContext = context;
        this.recyclerView = recyclerView;

        refreshListData(id, true);
    }

    // 刷新列表数据
    public void refreshListData(Long id, boolean isFrist) {
        this.goalId = id;
        if (!isFrist) {
            // 用于刷新
            int previousSize = mDatas.size();
            this.mDatas.clear();
            notifyItemRangeRemoved(0, previousSize + START_COUNT + END_COUNT);
            this.mDatas.addAll(ServiceFactory.getInstance().getGoalsService().findGoalEventForDetail(id));
            notifyItemRangeInserted(0, getItemCount());
        } else {
            // 用于初始化
            this.mDatas.addAll(ServiceFactory.getInstance().getGoalsService().findGoalEventForDetail(id));
        }
    }

    public void addItem(int position, GoalsEventVo item) {

        item = ServiceFactory.getInstance().getGoalsService().addGoalEvent(item);
        mDatas.add(position, item);

        // 因添加了头尾布局，所以需要加上顶部
        notifyItemInserted(position + START_COUNT);
    }

    public void updateItem(int position, Event e) {
        mDatas.set(position - START_COUNT, GoalsEventVo.convertEvent(e));
        notifyItemChanged(position, GoalsEventVo.convertEvent(e));
    }

    @Override
    public int getItemCount() {
        return mDatas.size() + START_COUNT + END_COUNT;
    }

    public int getContentSize() {
        return mDatas.size();
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        if (viewType == TYPE_HEAD) {
            return new HeadHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_default_header, viewGroup, false));
        } else if (viewType == TYPE_CONTENT) {
            return new ItemViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_goalsdetail, viewGroup, false));
        } else if (viewType == TYPE_OPERATION) {
            return new OperationHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_goalsdetail_set, viewGroup, false));
        } else if (viewType == TYPE_RELATION) {
            return new RelationHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_goalsdetail_relation, viewGroup, false));
        } else if (viewType == TYPE_TAG) {
            return new TagHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_goalsdetail_tag, viewGroup, false));
        } else if (viewType == TYPE_REMARK) {
            return new RemarkHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_goalsdetail_remark, viewGroup, false));
        } else {
            return new ButtomHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_default_bottom, viewGroup, false));
        }
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder h, int position) {
        if (h instanceof ItemViewHolder) { // 内容
            ((ItemViewHolder) h).initData(mDatas.get(position - START_COUNT));
        } else if (h instanceof RemarkHolder) {
            ((RemarkHolder) h).initData();
        } else if (h instanceof TagHolder) {
            ((TagHolder) h).inflateLayoutWithTags();
        } else if (h instanceof OperationHolder) {
            ((OperationHolder) h).initLabData();
        }
    }

    public Context getmContext() {
        return mContext;
    }

    public final static int START_COUNT = 1;
    public final static int END_COUNT = 5;

    public final static int TYPE_HEAD = 0;
    public final static int TYPE_CONTENT = 1;
    public final static int TYPE_OPERATION = 2;
    public final static int TYPE_RELATION = 3;
    public final static int TYPE_TAG = 4;
    public final static int TYPE_REMARK = 5;
    public final static int TYPE_BOTTOM = 6;


    @Override
    public int getItemViewType(int position) {
        int contentSize = getContentSize() + START_COUNT;
        if (position == 0) { // 头部
            return TYPE_HEAD;
        } else if (position == contentSize) { // 下一步骤
            return TYPE_OPERATION;
        } else if (position == contentSize + 1) { // 操作
            return TYPE_RELATION;
        } else if (position == contentSize + 2) { // 关联
            return TYPE_TAG;
        } else if (position == contentSize + 3) { // 标签
            return TYPE_REMARK;
        } else if (position == contentSize + 4) { // 备注
            return TYPE_BOTTOM;
        } else {
            return TYPE_CONTENT;
        }
    }

    @Override
    public void onItemDismiss(int position, boolean isLeftSlide) {
        if (getItemViewType(position) != TYPE_CONTENT) {
            return;
        }

        GoalsEventVo vo = mDatas.get(position - START_COUNT);

        if (isLeftSlide) {
            // 删除
            AlertUtils.dialog(getmContext(),
                    String.format(getmContext().getResources().getString(R.string.alt_del_goal_event), vo.getTitle()),
                    getmContext().getResources().getString(R.string.op_delete),
                    getmContext().getResources().getString(R.string.op_cancel),
                    (dialog, which) -> {
                        ServiceFactory.getInstance().getGoalsService().delGoalEvent(vo.getId());
                        mDatas.remove(position - START_COUNT);
                        notifyItemRemoved(position);
                        notifyItemRangeChanged(0, getItemCount());
                    }, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            //notifyItemRangeChanged(0, getItemCount());
                            refreshListData(goalId, false);
                        }
                    });
        } else {
            // 快速排期
            if (ServiceFactory.getInstance().getEventService().eventIsJoinTask(vo.getId())) {
                if (vo.getFinish()) {
                    // 已排期事务如已完成，在移除时需要用户确认
                    AlertUtils.removeJoinDialog(getmContext(),
                            getmContext().getResources().getString(R.string.alt_remove_event_task),
                            (dialog, which) -> {
                                ServiceFactory.getInstance().getEventService().doRmoveJoinScheduleDelTask(vo.getId());
                                AlertUtils.showToast(getmContext(), R.string.alt_remove_join_task);
                                refreshListData(goalId, false);
                            }
                    );
                } else {
                    ServiceFactory.getInstance().getEventService().doRmoveJoinScheduleDelTask(vo.getId());
                    AlertUtils.showToast(getmContext(), R.string.alt_remove_join_task);
                }
            } else {
                ServiceFactory.getInstance().getEventService().doJoinScheduleAndCreateTask(vo.getId(), new Date());
                AlertUtils.showToast(getmContext(), R.string.alt_join_task);
            }
            //notifyItemRangeChanged(0, getItemCount());
            refreshListData(goalId, false);

            //平滑到操作项
            ((LinearLayoutManager) recyclerView.getLayoutManager()).scrollToPositionWithOffset(position, 0);
        }

    }

    @Override
    public void onItemMove(int fromPosition, int toPosition) {
        if (getItemViewType(fromPosition) != TYPE_CONTENT) {
            return;
        }

        if (fromPosition < toPosition) {
            for (int i = fromPosition - START_COUNT; i < toPosition - START_COUNT; i++) {
                Collections.swap(mDatas, i, i + 1);
            }
        } else {
            for (int i = fromPosition - START_COUNT; i > toPosition - START_COUNT; i--) {
                Collections.swap(mDatas, i, i - 1);
            }
        }
        notifyItemMoved(fromPosition, toPosition);
    }


    // 中间的内容
    public class ItemViewHolder extends RecyclerView.ViewHolder implements ItemTouchHelperViewHolder {

        @BindView(R.id.labTitle)
        ClickableTextView labTitle;
        @BindView(R.id.rootLayout)
        LinearLayout rootLayout;
        @BindView(R.id.tagFinish)
        TextView tagFinish;
        @BindView(R.id.labScheduDt)
        TextView labScheduDt;
        @BindView(R.id.barSchedule)
        LinearLayout barSchedule;

        private GoalsEventVo data;

        public void initData(GoalsEventVo data) {
            this.data = data;
            labTitle.setText(data.getTitle());
            if (TextUtils.isEmpty(data.getScheduDt())) {
                labScheduDt.setVisibility(View.GONE);
                barSchedule.setVisibility(View.GONE);
            } else {
                labScheduDt.setVisibility(View.VISIBLE);
                labScheduDt.setText(data.getScheduDt());
                barSchedule.setVisibility(View.VISIBLE);
            }
            tagFinish.setVisibility(data.getFinish() ? View.VISIBLE : View.GONE);
        }

        public ItemViewHolder(final View v) {
            super(v);
            ButterKnife.bind(this, v);
        }

        @OnClick({R.id.labTitle, R.id.labScheduDt})
        public void onViewClicked(View view) {
            switch (view.getId()) {
                case R.id.labTitle:

                    if (goalId == null || goalId == 0) {
                        AlertUtils.showToast(view.getContext(), R.string.need_insert_content);
                        return;
                    }

                    QucikAddActivity.openEditorNoRepeatAndSetFinish(
                            getmContext(),
                            new QuickAddEditorCallback() {
                                @Override
                                public void onCancel() {
                                    Event e = ServiceFactory.getInstance().getEventService().getEventDao().load(data.getId());
                                    updateItem(getAdapterPosition(), e);
                                }

                                @Override
                                public void onSubmit(String title) {
                                    if (TextUtils.isEmpty(title)) {
                                        return;
                                    }
                                    Event e = ServiceFactory.getInstance().getEventService().updateEventTitle(data.getId(), title);
                                    updateItem(getAdapterPosition(), e);
                                }

                                @Override
                                public void onAttached(final ViewGroup rootView) {
                                    QucikAddEditText etContent = rootView.findViewById(R.id.quick_add_task_content_edt);
                                    etContent.setText(data.getTitle());
                                }
                            },
                            new QuickAddHolder(QuickAddHolder.QuickAddType.EVENT_UPDATE),
                            new QucikAddInputCheckRule(120, 2),
                            data.getFinish(),
                            new ExpansionCallback() {
                                @Override
                                public void onFinish(Context context, boolean isFinish, ChangeViewCallback changeViewCallback) {
                                    if (isFinish) {
                                        AlertUtils.showToast(context, "请指定事件完成时间");
                                        DatePickDialog dialog = new DatePickDialog(context);
                                        dialog.setYearLimt(5);
                                        dialog.setType(DateType.TYPE_ALL);
                                        dialog.setStartDate(new Date());
                                        dialog.setOnChangeLisener(null);
                                        dialog.setOnSureLisener(new OnSureLisener() {
                                            @Override
                                            public void onSure(Date finishDt) {
                                                //AlertUtils.showToast(context, DateUtils.date2str(finishDt, DateType.TYPE_ALL.getFormat()));
                                                ServiceFactory.getInstance().getEventService().doCreateTaskAndSetFinish(data.getId(), true, finishDt);
                                                changeViewCallback.onChangeView(true);
                                            }
                                        });
                                        dialog.show();
                                    } else {
                                        ServiceFactory.getInstance().getEventService().doCreateTaskAndSetFinish(data.getId(), false, null);
                                        changeViewCallback.onChangeView(true);
                                    }
                                }
                            }
                    );

                    break;
                case R.id.labScheduDt:
                    if (data != null && data.getId() != null) {
                        Task task = ServiceFactory.getInstance().getEventService().findEventTask(data.getId());
                        if (task != null) {
                            Intent intent = new Intent(view.getContext(), TaskDetailActivity.class);
                            intent.putExtra(TaskDetailActivity.PARAMS_KEY, task.getId());
                            ((Activity) getmContext()).startActivityForResult(intent, 1002);
                        }
                    }
                    break;
            }
        }

        @Override
        public void onItemSelected(Context context) {

        }

        @Override
        public void onItemClear(Context context) {

        }
    }


    // 操作
    public class OperationHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.btnChoiceType)
        TextView btnChoiceType;
        @BindView(R.id.btnChoiceData)
        TextView btnChoiceData;

        private PopupMenu menuGoalType;
        private int goalRange = 0;
        private int rangeYear = 0;
        private int rangeMonth = 0;
        private int rangeQuarter = 0;

        public OperationHolder(final View v) {
            super(v);
            ButterKnife.bind(this, v);


            menuGoalType = new PopupMenu(mContext, btnChoiceType);
            menuGoalType.inflate(R.menu.menu_goaltype);

            btnChoiceType.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (goalId == null || goalId == 0) {
                        AlertUtils.showToast(itemView.getContext(), R.string.need_insert_content);
                        return;
                    }
                    menuGoalType.show();
                }
            });

            menuGoalType.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    switch (item.getItemId()) {
                        case R.id.goalstype_item1:
                            goalRange = AppStatus.GoalsRange.MONTHLY;
                            setDateLabAndSaveData(new Date());
                            break;
                        case R.id.goalstype_item2:
                            goalRange = AppStatus.GoalsRange.QUARTER;
                            setDateLabAndSaveData(DateUtils.getYearQuarterNumber(new Date()));
                            break;
                        case R.id.goalstype_item3:
                            goalRange = AppStatus.GoalsRange.YEAR;
                            setDateLabAndSaveData(new Date());
                            break;
                    }
                    btnChoiceType.setText(String.format(v.getResources().getString(R.string.goalstype_x), item.getTitle()));

                    return false;
                }
            });

            btnChoiceData.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (goalId == null || goalId == 0) {
                        AlertUtils.showToast(itemView.getContext(), R.string.need_insert_content);
                        return;
                    }

                    DateType type = getDateType();

                    DatePickDialog dialog = new DatePickDialog(mContext);
                    dialog.setYearLimt(5);
                    dialog.setType(type);
                    setDefaultVal(dialog);
                    dialog.setOnChangeLisener(null);
                    dialog.setOnSureLisener(new OnSureLisener() {
                        @Override
                        public void onSure(Date date) {
                            // 默认类型的回调
                            setDateLabAndSaveData(date);
                        }
                    });
                    dialog.setOnCustomSureLisener(new OnCustomSureLisener() {
                        @Override
                        public void onSure(Object obj) {
                            // 自定义类型的回调
                            setDateLabAndSaveData(obj);
                        }
                    });
                    dialog.show();
                }
            });

        }

        private void initLabData() {
            Goals t = ServiceFactory.getInstance().getGoalsService().getGoalsDao().load(goalId);
            if (t == null) {
                t = ServiceFactory.getInstance().getGoalsService().getDefaultGoals();
            }
            goalRange = t.getGoalsRange();
            rangeYear = t.getRangeYear();
            rangeQuarter = t.getRangeQuarter();
            rangeMonth = t.getRangeMonthly();

            switch (goalRange) {
                case AppStatus.GoalsRange.YEAR:
                    btnChoiceType.setText(menuGoalType.getMenu().findItem(R.id.goalstype_item3).getTitle());
                    btnChoiceData.setText(String.format(mContext.getResources().getString(R.string.goalsdata_x3), rangeYear));
                    break;
                case AppStatus.GoalsRange.QUARTER:
                    btnChoiceType.setText(menuGoalType.getMenu().findItem(R.id.goalstype_item2).getTitle());
                    btnChoiceData.setText(String.format(mContext.getResources().getString(R.string.goalsdata_x2), rangeYear, rangeQuarter));
                    break;
                default:
                    btnChoiceType.setText(menuGoalType.getMenu().findItem(R.id.goalstype_item1).getTitle());
                    btnChoiceData.setText(String.format(mContext.getResources().getString(R.string.goalsdata_x1), rangeYear, rangeMonth));
                    break;
            }
        }

        private DateType getDateType() {
            DateType type;
            switch (goalRange) {
                case AppStatus.GoalsRange.QUARTER:
                    type = DateType.TYPE_CUSTOM_YEAR_QUARTER;
                    break;
                case AppStatus.GoalsRange.YEAR:
                    type = DateType.TYPE_Y;
                    break;
                default:
                    type = DateType.TYPE_YM;
                    break;
            }
            return type;
        }

        private void setDefaultVal(DatePickDialog d) {
            switch (goalRange) {
                case AppStatus.GoalsRange.QUARTER:
                    // TYPE_CUSTOM_YEAR_QUARTER
                    d.setStartData((rangeYear * 100 + rangeQuarter));
                    break;
                case AppStatus.GoalsRange.YEAR:
                    // TYPE_Y
                    d.setStartDate(DateUtils.getDate(rangeYear, 1, 1, 0, 0));
                    break;
                default:
                    // TYPE_YM
                    d.setStartDate(DateUtils.getDate(rangeYear, rangeMonth, 1, 0, 0));
                    break;
            }
        }

        private void setDateLabAndSaveData(Object selObj) {
            switch (goalRange) {
                case AppStatus.GoalsRange.YEAR:
                    goalRange = AppStatus.GoalsRange.YEAR;
                    rangeYear = DateUtils.getYear((Date) selObj);
                    rangeQuarter = 0;
                    rangeMonth = 0;
                    btnChoiceData.setText(String.format(mContext.getResources().getString(R.string.goalsdata_x3), rangeYear));
                    break;
                case AppStatus.GoalsRange.QUARTER:
                    goalRange = AppStatus.GoalsRange.QUARTER;
                    rangeYear = Integer.parseInt(String.valueOf(selObj).substring(0, 4));
                    rangeQuarter = Integer.parseInt(String.valueOf(selObj).substring(4));
                    rangeMonth = 0;
                    btnChoiceData.setText(String.format(mContext.getResources().getString(R.string.goalsdata_x2), rangeYear, rangeQuarter));
                    break;
                default:
                    goalRange = AppStatus.GoalsRange.MONTHLY;
                    rangeYear = DateUtils.getYear((Date) selObj);
                    rangeMonth = DateUtils.getMoth((Date) selObj);
                    rangeQuarter = 0;
                    btnChoiceData.setText(String.format(mContext.getResources().getString(R.string.goalsdata_x1), rangeYear, rangeMonth));
                    break;
            }

            // 保存数据
            ServiceFactory.getInstance().getGoalsService().saveGoalType(goalId, goalRange, rangeYear, rangeQuarter, rangeMonth);
        }

    }

    // 关联管理
    public class RelationHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.rootLayout)
        LinearLayout rootLayout;

        public RelationHolder(View v) {
            super(v);
            ButterKnife.bind(this, v);
        }

        @OnClick({R.id.rootLayout})
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.rootLayout:
                    if (goalId == null || goalId == 0) {
                        AlertUtils.showToast(itemView.getContext(), R.string.need_insert_content);
                        return;
                    }

                    Intent intent = new Intent(v.getContext(), GoalsTraceSourceActivity.class);
                    intent.putExtra(GoalsTraceSourceActivity.PARAMS_KEY, goalId);
                    v.getContext().startActivity(intent);
                    break;
                default:
                    break;
            }
        }
    }

    // 标签管理
    public class TagHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tagLayout)
        FlexboxLayout tagLayout;
        @BindView(R.id.labHint)
        TextView labHint;

        public TagHolder(View v) {
            super(v);
            ButterKnife.bind(this, v);
        }

        @OnClick({R.id.layoutEnter})
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.layoutEnter:

                    if (goalId == null || goalId == 0) {
                        AlertUtils.showToast(itemView.getContext(), R.string.need_insert_content);
                        return;
                    }

                    Intent intent = new Intent(getmContext(), GoalsTagActivity.class);
                    intent.putExtra(GoalsTagActivity.PARAMS_KEY, goalId);
                    intent.putExtra(GoalsTagActivity.PARAMS_POSITION, getAdapterPosition());
                    ((Activity) getmContext()).startActivityForResult(intent, 1004);
                    break;
                default:
                    break;
            }
        }

        private void inflateLayoutWithTags() {
            tagLayout.removeAllViews();

            if (goalId == null) {
                return;
            }

            List<TagVo> tags = ServiceFactory.getInstance().getTagService().findTagForGoal(goalId, false);
            if (tags.size() > 0) {
                labHint.setVisibility(View.GONE);

                for (TagVo vo : tags) {
                    View tagView = LayoutInflater.from(itemView.getContext()).inflate(R.layout.single_tag, null);
                    Chip tag = tagView.findViewById(R.id.tag);
                    tag.setChipText(vo.getTitle());
                    tag.setSelectable(false);
                    tagLayout.addView(tagView);
                }
            } else {
                labHint.setVisibility(View.VISIBLE);
            }
        }
    }

    // 备注
    public class RemarkHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.labRemark)
        TextView labRemark;
        @BindView(R.id.labRemarkDt)
        TextView labRemarkDt;

        RemarkHolder(View v) {
            super(v);
            ButterKnife.bind(this, v);
        }

        @OnClick({R.id.remarkLayout})
        public void onViewClicked(View v) {
            switch (v.getId()) {
                case R.id.remarkLayout:

                    if (goalId == null || goalId == 0) {
                        AlertUtils.showToast(itemView.getContext(), R.string.need_insert_content);
                        return;
                    }

                    Intent intent = new Intent(getmContext(), GoalsRemarkActivity.class);
                    intent.putExtra(GoalsRemarkActivity.PARAMS_KEY, goalId);
                    intent.putExtra(GoalsRemarkActivity.PARAMS_POSITION, getAdapterPosition());
                    ((Activity) getmContext()).startActivityForResult(intent, 1005);
                    break;
                default:
                    break;
            }
        }

        public void initData() {
            if (goalId != null && goalId != 0) {
                Remark r = ServiceFactory.getInstance().getRemarkService().getRemark(AppStatus.RemarkType.GOALS, goalId);
                if (r != null) {
                    labRemark.setText(r.getContent());
                    labRemarkDt.setText(String.format(getmContext().getResources().getString(R.string.update_time), DateUtils.date2str(r.getUpdatedDt(), DateUtils.F31)));
                    labRemarkDt.setVisibility(View.VISIBLE);
                } else {
                    labRemark.setText("");
                    labRemarkDt.setVisibility(View.GONE);
                }
            } else {
                labRemarkDt.setVisibility(View.GONE);
            }
        }
    }

    // 头部内容
    public class HeadHolder extends RecyclerView.ViewHolder {
        public HeadHolder(View itemView) {
            super(itemView);
        }
    }

    // 尾部内容
    public class ButtomHolder extends RecyclerView.ViewHolder {
        public ButtomHolder(View itemView) {
            super(itemView);
        }
    }

}
